package org.openqa.selenium.profiler.testserver;

import org.webbitserver.HttpControl;
import org.webbitserver.HttpHandler;
import org.webbitserver.HttpRequest;
import org.webbitserver.HttpResponse;
import org.webbitserver.WebServer;

public class RunOnceHandler implements HttpHandler {

  private final HttpHandler delegate;
  private WebServer server;

  public RunOnceHandler(HttpHandler delegate) {
    this.delegate = delegate;
  }

  @Override
  public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control)
      throws Exception {
    delegate.handleHttpRequest(request, response, control);
    this.server.stop();
  }

  public void setServer(WebServer server) {
    this.server = server;
  }

}
